import {
  collectionList,
  userCollectAbroadSchool
} from '../../network/interface.js';


Page({

  /**
   * 页面的初始数据
   */
  data: {
    schools: []
  },

  

  //收藏学校
  collectSchool(e) {
    let params={};
    let that =this;
    let schoolId=e.target.dataset.param;
    params.schoolId=schoolId;
    let userInfo = wx.getStorageSync('userInfo');
    if (userInfo) {
      params.userId = userInfo.userId;
    }
    params.status=1;
    userCollectAbroadSchool(params,function success(res) {
      if (res['status']==200) {
          wx.showToast({
            title: '收藏成功',
          })
      }
      that.onShow();
    },function fail(res) {
      
    })
  },
  //取消收藏
  cancelCollectSchool(e){
    let params={};
    let that =this;
    let schoolId=e.target.dataset.param;
    params.schoolId=schoolId;
    let userInfo = wx.getStorageSync('userInfo');
    if (userInfo) {
      params.userId = userInfo.userId;
    }
    params.status=2;
    userCollectAbroadSchool(params,function success(res) {
      if (res['status']==200) {
          wx.showToast({
            title: '取消成功',
          })
      }
      that.onShow();
    },function fail(res) {
      
    })
  },


  onShow: function () {
    let that = this;
    let params = {};
    let userInfo = wx.getStorageSync('userInfo');
    if (userInfo) {
      params.userId = userInfo.userId;
    }
    collectionList(params, function success(res) {
      if (res['status'] === 200) {
        console.log(res)
        that.setData({
          schools: res['data']
        })

      }
    }, function fail(res) {

    })
  },

  onPullDownRefresh(){
    wx.showNavigationBarLoading();
    let that=this;
    that.onShow();
  }
})